<template>
  <s-layout id="layout" :title="'我的日周月报'" navbar="normal" leftIconColor="#333" :autoBack="false"
 :bgColor="state.bgColor" :tabbarshow='false'
		:titleStyle="{ color: '#333', fontSize: '32rpx' }">
  <view class="call_on list_box" :style="{paddingTop:(safeAreaInsets?.top + 44) + 'px'}">
    <view class="menu">
      <up-tabs :list="state.menulist" @click="menulistclick" 	:current="state.currentTab"></up-tabs>
      <view class="serch_date">
        <view class="serch_date_left">
          <up-text prefixIcon="clock" iconStyle="font-size: 19px" text="百度一下,你就知道"></up-text>
        </view>
        <view class="right">
          
        </view>
        
      </view>
    </view>
    <scroll-view   scroll-y class="comprehensive"  v-if="list.length" @scrolltolower='listScrolltolower' >
      <view class="item_wrap" >
        <view class="item" v-for="(item,index) in list" :key="index">
          <view class="item_left">
            <view class="item_left_box">
              <view class="status" v-if="item.status !==0">
                {{ item.state == 0?'待审批':item.state == 1?'已审批'
                :item.state == 2?'已拒绝':item.state == 3?'审批中':'' }}
              </view>
              <view class="title">{{item.title }}</view>
            </view>
            <view class="item_left_box">
              <text class="name">{{item.salary }}元</text> 
            </view>
            <view class="item_left_box">
              <image class="time_name_img"
												:src="`${baseUrl}/uploads/uniapp_image/staff/Myinvite_icon_time.png`" />
              <text class="time_name">{{formatDatetime(item.createtime) }}</text> 
            </view>
          </view>
          <view class="item_right">
            <text class="name">查看详情</text>
            <u-icon size="10" name="arrow-right" color="#0038F7" ></u-icon>
          </view>
        </view>

      </view>
        <!-- 正在加载组件 -->
      <view>
        <s-loadmore-gather :current_page="listPage" :last_page="listlast_page" ref="loadmoreRef"></s-loadmore-gather>
      </view>
    </scroll-view>
    
    <u-empty v-else mode="list"  icon="http://cdn.uviewui.com/uview/empty/list.png" text="暂无内容" marginTop="50%"></u-empty>
  </view>

  </s-layout>
</template>

<script setup>
import { baseUrl } from '@/sheep/config';
import sheep from '@/sheep';
import { onLoad,onReachBottom } from "@dcloudio/uni-app";
import { ref ,reactive } from 'vue';
import Button from '@/components/s-button/s-button';
import {
  formatDatetime
	} from '@/utils/fn.js';
const { safeAreaInsets } = uni.getSystemInfoSync()
const state =  ref({
  bgColor:'#fff',
  menulist:[
  { name: '日报',value:'0' },  
  { name: '周报',value:'1' },  
  { name: '月报',value:'1' },  
  ],
  currentTab:'0'
})

const  list = ref([])
const listPage = ref()
const listlast_page = ref();
const listpagenumber = ref(1);
onLoad((options) => {
  getRecruitmentList()
})

// 1.
const loadmoreRef = ref()

//点击切换菜单  
const  menulistclick = (e) =>{
    list.value = [];
		state.currentTab = e.value;
		listpagenumber.value = 1;
    getRecruitmentList()
}
//数据请求

const getRecruitmentList =  () => {
  let status;
		if (state.currentTab == '0') {
			status = '';
		}
		if (state.currentTab == '1') {
			status = '0';
		}
		if (state.currentTab == '2') {
			status = '1';
		}
		if (state.currentTab == '3') {
			status = '2';
		}
		if (state.currentTab == '4') {
			status = '3';
		}
		let obj = {
			state: status,
		};

		let params = {
			filter: JSON.stringify(obj),
			op: JSON.stringify({
				state: '=',
			}),
			is_private: 1,
			page: listpagenumber.value,
		};
  sheep.$api.recruit.getRecruitmentList(params).then((res)=>{
    list.value = [...list.value, ...res?.data.rows];
    listPage.value = res.data.current_page
		listlast_page.value = res.data.last_page
  });
  
}

  //滚动触底
  const listScrolltolower = () => {
    // 2.
    loadmoreRef.value.PopupScrolltolower()
          if (listPage.value < listlast_page.value) {
          listpagenumber.value += 1;
        } else {
           return;
          }
        getRecruitmentList();
    };

</script>

<style lang="scss" scoped>
// 滚动
.comprehensive{
        width: calc(100% - 40rpx);
        background-color: rgba(0, 0, 0, 0);
        margin: 0 20rpx;
        height: 70vh;
}
//列表
.call_on{
  width: 100%;
  height: 89vh;
  .list_box{
    width: 100%;
    height: auto;
  }

}
.loading-text {
		text-align: center;
		font-size: $uni-font-size-base;
		color: #666;
		padding: 20rpx 0 50rpx;
	}
  // 列表内容
  .item_wrap{
    margin-top: 20rpx;
    .item{
      margin-bottom: 20rpx;
      border-radius: 16rpx;
      background-color: #FFFFFF;
      box-shadow: 0 4rpx 8rpx 0 rgba(0, 0, 0, 0.05);
      display: flex;
      // justify-content: space-around;
      align-items: center;
      .item_left{
        width: 75%;
        padding: 25rpx 0 16rpx 30rpx;
        height: 168rpx;
        flex-direction: column;
        font-family: PingFangSC;
        color: $uni-text-color;
        .item_left_box{
          display: flex;
          .status {
            width: 104rpx;
            height: 36rpx;
            font-family: PingFangSC;
            color: $uni-color-primary;
            font-weight: 500;
            font-size: 22rpx;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 18rpx;
            margin-right: 10rpx;
            background-color: rgba(0, 56, 247, 0.1);
          }
          .title{
            font-weight: $uni-font-weight;
            font-size: $uni-font-size-base;
            margin-bottom: 10rpx;
            width: 88%;
            height: 50rpx;
            white-space: nowrap; 
            overflow: hidden; 
            text-overflow: ellipsis; 
            }
            .name{
              font-family: PingFangSC;
              color: #666666;
              font-weight: 400;
             font-size:$uni-font-size-26;
            }
            .time_name_img{
              width: 24rpx;
              height: 24rpx;
              margin-right: 10rpx;
            }
            .time_name{
              font-family: PingFangSC;
              color: #999999;
              font-weight: 500;
              font-size: $uni-font-size-sm;
            }
            &:last-child{
              margin: 30rpx 0;
              align-items: center;
            }
        }
        
        .name_and_phone{
          .name{margin-right: 8rpx;}
         display: flex;
         align-items: center;
          color: #666666;
          font-weight: 400;
         font-size:$uni-font-size-26;
          margin-bottom: 20rpx;
        }
        .addresss{
          image{width: 18rpx; height: 26rpx; margin-right: 8rpx;}
          display: flex;
          align-items: center;
          color: #999999;
          font-weight: 500;
          font-size: $uni-font-size-sm;
        }

      }
      .item_right{
        padding-right: 30rpx;
        font-family: PingFangSC;
        color: $uni-color-primary;
        font-weight: 400;
        font-size: 22rpx;
        display: flex;
        .name{
          margin-right: 6rpx;
        }
      }
    }
  }
  .menu{
    width: 100%;
    height: 98rpx;
    background: $uni-bg-color;
    :deep(.u-tabs__wrapper__nav__item ){
      width: 14%;
    }
    :deep(.u-tabs__wrapper__nav__line){
      width: 30rpx !important;
      height: 8rpx !important;
      border-radius: 4rpx !important;
background: linear-gradient(90deg, rgba(0, 56, 247, 1) 0%, rgba(77, 139, 255, 1) 100%) !important;
    }
  }
</style>